forum

home / developersection / forums / catch multiple exceptions at once?

Catch multiple Exceptions at once?

Pravesh Singh 2648 13-Jun-2013

It is discouraged to simply catch System.Exception, instead only the "known" Exceptions should be caught.

Now, this sometimes leads to unneccessary repetetive code, for example:

try
{
    WebId = new Guid(queryString["web"]);
}
catch (FormatException)
{
    WebId = Guid.Empty;
}
catch (OverflowException)
{
    WebId = Guid.Empty;
}

I wonder: Is there a way to catch both Exceptions and only call the WebId =

Guid.Empty call once?


c# c# 
Updated on 13-Jun-2013

Student

Can you answer this question?

Answer

1 Answers

Liked By